#!/bin/sh

min_port=$1
max_port=$2

if [ -z "$min_port" ]; then
    min_port=5000
fi

if [ -z "$max_port" ]; then
    max_port=5005
fi

base_path=`pwd`/..

echo 'min_port='$min_port 'max_port='$max_port 'base_path='$base_path

for port in `seq $min_port $max_port`; do
  path=${base_path}/redis${port}/data

  mkdir -p ${path}

#  if [ -e ${path}/nodes.conf ]; then
#    rm ${path}/nodes.conf
#  fi

  PORT=${port} BASE_PATH=${path} envsubst < ./redis-cluster-native.conf.tmpl > ${path}/redis.conf

  PORT=${port} envsubst < ./native-run.sh.tmpl > ${path}/../native-run.sh

  chmod +x ${path}/../native-run.sh
done